﻿using AutoMapper;
using Domain.Flow;
using MediatR;
using U.B.ErrorCode;
using U.B.Repistory;
using U.B.WriteApi.Command.RabbitBWss;

namespace U.B.WriteApi.CommandHander.RabbitBWDD
{
    public class AddFirmsCommandHander : IRequestHandler<AddFirmsCommand, ApiResult<object>>
    {
        public readonly IRepistory<Firm> FirmRepistory;
        public readonly IMapper Mapper;

        public AddFirmsCommandHander(IRepistory<Firm> firmRepistory, IMapper mapper)
        {
            FirmRepistory = firmRepistory;
            Mapper = mapper;
        }
        /// <summary>
        /// 企业添加
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public Task<ApiResult<object>> Handle(AddFirmsCommand request, CancellationToken cancellationToken)
        {
            ApiResult<object> apiresult = new ApiResult<object>();
            var result= FirmRepistory.Add(Mapper.Map<Firm>(request));
            apiresult.Data = result;
            apiresult.Message = Renum.添加成功.ToString();
            apiresult.code = Renum.添加成功;
            return Task.FromResult(apiresult);
        }
    }
}
